import ffmpeg
import os

def get_video_info(source_video_path):
    probe = ffmpeg.probe(source_video_path)
    print('source_video_path: {}'.format(source_video_path))
    format = probe['format']
    bit_rate = int(format['bit_rate'])/1000
    duration = format['duration']
    size = int(format['size'])/1024/1024
    video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
    if video_stream is None:
        print('No video stream found!')
        return
    width = int(video_stream['width'])
    height = int(video_stream['height'])
    num_frames = int(video_stream['nb_frames'])
    fps = int(video_stream['r_frame_rate'].split('/')[0])/int(video_stream['r_frame_rate'].split('/')[1])
    duration = float(video_stream['duration'])
    print('width: {}'.format(width))
    print('height: {}'.format(height))
    print('num_frames: {}'.format(num_frames))
    print('bit_rate: {}k'.format(bit_rate))
    print('fps: {}'.format(fps))
    print('size: {}MB'.format(size))
    print('duration: {}'.format(duration))



if __name__ == "__main__":
    video_path = 'D:/BoBO/WorkFlow/custom/python/test2.mp4'
    # print(video_path)
    get_video_info(video_path)